package com.jidu.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jidu.common.annotation.RepeatSubmit;
import com.jidu.domain.SysStudent;
import com.jidu.domain.dto.ApplyStudentDto;
import com.jidu.service.ISysStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.jidu.common.annotation.Log;
import com.jidu.common.core.controller.BaseController;
import com.jidu.common.core.domain.AjaxResult;
import com.jidu.common.enums.BusinessType;
import com.jidu.common.utils.poi.ExcelUtil;
import com.jidu.common.core.page.TableDataInfo;

/**
 * 学员Controller
 * 
 * @author ruoyi
 * @date 2024-07-19
 */
@Slf4j
@Api(tags = "学员 controller")
@RestController
@RequestMapping("/system/student")
public class SysStudentController extends BaseController
{
    @Autowired
    private ISysStudentService sysStudentService;

    /**
     * 查询学员列表
     */
    @ApiOperation(value = "查询学员列表")
    @PreAuthorize("@ss.hasPermi('system:student:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysStudent sysStudent)
    {
        startPage();
        List<SysStudent> list = sysStudentService.selectSysStudentList(sysStudent);
        return getDataTable(list);
    }

    /**
     * 导出学员列表
     */
    @ApiOperation(value = "导出学员列表")
    @PreAuthorize("@ss.hasPermi('system:student:export')")
    @Log(title = "学员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysStudent sysStudent)
    {
        List<SysStudent> list = sysStudentService.selectSysStudentList(sysStudent);
        ExcelUtil<SysStudent> util = new ExcelUtil<SysStudent>(SysStudent.class);
        util.exportExcel(response, list, "学员数据");
    }

    /**
     * 获取学员详细信息
     */
    @ApiOperation(value = "获取学员详细信息")
    @PreAuthorize("@ss.hasPermi('system:student:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysStudentService.selectSysStudentById(id));
    }

    /**
     * 新增学员
     */
    @ApiOperation(value = "新增学员")
    @PreAuthorize("@ss.hasPermi('system:student:add')")
    @Log(title = "学员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysStudent sysStudent)
    {
        return toAjax(sysStudentService.insertSysStudent(sysStudent));
    }

    /**
     * 修改学员
     */
    @ApiOperation(value = "修改学员")
    @PreAuthorize("@ss.hasPermi('system:student:edit')")
    @Log(title = "学员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysStudent sysStudent)
    {
        return toAjax(sysStudentService.updateSysStudent(sysStudent));
    }

    /**
     * 删除学员
     */
    @ApiOperation(value = "删除学员")
    @PreAuthorize("@ss.hasPermi('system:student:remove')")
    @Log(title = "学员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysStudentService.deleteSysStudentByIds(ids));
    }

    /**
     * 报名
     */
    @RepeatSubmit
    @Log(title = "学员报名", businessType = BusinessType.INSERT)
    @ApiOperation(value = "学员报名")
    @PostMapping("/apply")
    public AjaxResult apply(@RequestBody ApplyStudentDto dto){
        return AjaxResult.success(sysStudentService.apply(dto));
    }

    /**
     * 学员列表
     */
    @ApiOperation(value = "学员列表")
    @GetMapping("/stuList")
    public TableDataInfo studentList(ApplyStudentDto dto){
        startPage();
        return getDataTable(sysStudentService.studentList(dto));
    }

    /**
     * 回显
     */
    @ApiOperation(value = "学员课程修改回显")
    @GetMapping("/getInfo")
    public AjaxResult getStudentCourse(@RequestParam(value = "studentId") Long studentId,@RequestParam(value = "courseStudentId") Long courseStudentId){
        return AjaxResult.success(sysStudentService.getStudentCourse(studentId,courseStudentId));
    }



    /**
     * 编辑
     */
    @ApiOperation(value = "学生课程修改")
    @PutMapping("/update")
    public AjaxResult exit(@RequestBody ApplyStudentDto applyStudentDto){
        return AjaxResult.success(sysStudentService.exit(applyStudentDto));
    }


    /**
     * 工作台数据看板
     */
    @ApiOperation(value = "工作台数据看板")
    @GetMapping("/data")
    public AjaxResult dataBoard(){
        return AjaxResult.success(sysStudentService.dataBoard());
    }



}
